<?php
    $currentSeason = $seasonStart . ' - ' . ($seasonStart+1);
    $data = array();
    $dataSavePoints = array();
    $categories = array();

    $i = 0;
    foreach($licensee_point_list as $licenseePoint){

        if(!empty($licenseePoint[ 'nb_points_fftt' ])){
            $data[] = intval($licenseePoint[ 'nb_points_fftt' ]);
        }else{
            $data[] = end($data);
        }

        if(!empty($licenseePoint[ 'nb_points' ])){
            $dataSavePoints[] = intval($licenseePoint[ 'nb_points' ]);
        }else if(!empty($licenseePoint[ 'nb_points_fftt' ])){
            $dataSavePoints[] = intval($licenseePoint[ 'nb_points_fftt' ]);
        }

        $datetime_points = new DateTime();
        $month = date('m', strtotime($licenseePoint[ 'datetime_points' ])) - 1;
        $year = date('Y', strtotime($licenseePoint[ 'datetime_points' ]));
        if($month < 1){
            $month = 12;
            $year--;
        }
        $datetime_points->setDate($year, $month, '01');
        $datetime_points->setTime(0, 0, 0);

        $categories[] = date("M", $datetime_points->getTimestamp()) . ".";
    }

    $mensualPoint = "-";
    $evoMensualPoint = "-";
    
    if(count( $dataSavePoints ) > 0){
        $mensualPoint = end($dataSavePoints);
        $evoMensualPoint = end($dataSavePoints) - prev($dataSavePoints);
    }
    $data = json_encode( $data );
    $dataSavePoints = json_encode( $dataSavePoints );

    $categories = json_encode( $categories );
?>

<script type="text/javascript">
    var data = <?php echo $data ?>;
    var dataSavePoints = <?php echo $dataSavePoints ?>;
    var categories = <?php echo $categories ?>;
</script>

<?php include_partial('member/profilMenuTop', array('member_info' => $member_info, 'selected' => 3)); ?>

<h1 class="title">Evolution mensuelle saison <?php echo $currentSeason ?></h1>
<p>
    <select onChange="window.location.href=this.options[this.selectedIndex].value">
        <option value="">Visualisez une autre saison : </option>
        <?php $min_date = date('Y', strtotime($season_list['min_date'])) ?>
        <?php $max_date = date('Y', strtotime($season_list['max_date'])) ?>

        <?php for($i=$min_date; $i<$max_date+1; $i++): ?>

            <?php
                $link = "";
                if($sf_user->isAuthenticated() && $sf_user->getGuardUser()->getId() == $member_info[ 'sfGuardUserProfile' ][ 'User' ][ 'id' ]):
                    $link = url_for('@member_myEvolution_changeSeason?seasonStart=' . $i . '&seasonEnd=' . ($i+1));
                else:
                    $link = url_for('@member_evolution_changeSeason?name_slug=' . $member_info[ 'slug' ]. '&seasonStart=' . $i . '&seasonEnd=' . ($i+1));
                endif;
            ?>

            <option value="<?php echo $link ?>">Saison <?php echo $i ?> - <?php echo $i+1 ?></option>
        <?php endfor; ?>

    </select>
</p>
<br /><br />

<div id="evolutionGraph"></div>

<div class="push_float"></div>